package com.briup.jd2511.jd2511bookstore.aspect;


import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Aspect
@Slf4j
public class MyAspect6 {

    @Before("com.briup.jd2511.jd2511bookstore.aspect.MyAspect5.anpc()")
    public void before(JoinPoint joinPoint){
        log.info("MyAspect6 before");
        System.out.println(joinPoint.getSignature().getName());
    }

    @After("com.briup.jd2511.jd2511bookstore.aspect.MyAspect5.anpc()")
    public void after(JoinPoint joinPoint){
        log.info("MyAspect6 after");
        System.out.println(joinPoint.getSignature().getName());
    }

    @Around("com.briup.jd2511.jd2511bookstore.aspect.MyAspect5.anpc()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        // 1、获取target
        Object target = joinPoint.getTarget();
        log.info("MyAspect6 around target:{}",target.getClass());
        // 2、获取方法名字
        String name = joinPoint.getSignature().getName();
        log.info("MyAspect6 around method name:{}",name);
        // 3、获取方法参数
        Object[] args = joinPoint.getArgs();
        log.info("方法参数:{}", Arrays.toString(args));
        // 4、执行原始方法
        Object proceed = joinPoint.proceed();
        // 5、原始方法的返回值
        log.info("方法返回值：{}",proceed);
        // 6、输出返回值的json字符串形式
        String jsonString = JSON.toJSONString(proceed);
        System.out.println(jsonString);

        return proceed;
    }
}
